﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraControl : MonoBehaviour
{
    //private Transform camPos;

    private Transform hero;
    

    Vector3 offset;
    Vector3 v3;
    private void Update()
    {
        if(hero == null)
        {
            hero = GameObject.FindGameObjectWithTag("Player").transform;
            offset = transform.position - hero.position;
        }
        Vector3 targetPosition = hero.position + offset; //保持相对距离
        transform.position = targetPosition;//Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * 3);
        v3 = transform.position;    
        v3.x = Mathf.Clamp(v3.x, -21f, 21f);
        v3.z = Mathf.Clamp(v3.z, -121f, -71f);
        transform.position = v3;
    }


    //移动限制
    public bool MoveLimit()
    {
        return false;
    }

    public void SetPlayNull()
    {
        hero = null;
    }

}
